<?php
/*
  Copyright 2010 Mark Watkinson

  This file is part of Luminous.

  Luminous is free software: you can redistribute it and/or
  modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Luminous is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Luminous.  If not, see <http://www.gnu.org/licenses/>.

*/
/**
 * \file example.php
 * \brief A short example for calling Luminous
 */ 

require_once('luminous.php'); 

  
// Luminous shouldn't ever get caught in an infinite loop even on the most
// terrible and malformed input, but I think you'd be daft to run it with no
// safeguard. Also, if you allow your users to give it arbitrary inputs, large
// inputs are pretty much asking for a denial of service attack. Ideally you 
// would enforce your own byte-limit, but I think a time limit is also sensible.
set_time_limit(3);
  
$use_cache = !isset($_GET['nocache'])

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Luminous is HTML strict/loose and HTML5 valid //-->
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title> Example </title>
  <!-- if you forget this it won't look so good //-->
  <link rel="stylesheet" type="text/css" href="./style/luminous.css">

  <!-- This is the theme, this affects only colours. You may swap this for
anything else in the style folder (except the print stylesheet). -->
  <link rel='stylesheet' type='text/css' href='./style/luminous_light.css'>

  <!-- Luminous uses jQuery for javascript. You may put jQuery into 
    compatability mode if it clashes with another library you need. Make 
    sure you include jQuery before luminous.js.
  The javascript is entirely optional.
  //-->
  <script type='text/javascript' src='./client/jquery-1.4.2.min.js'></script>
  <script type='text/javascript' src='./client/luminous.js'></script>   
</head>

<body>

<h1> A simple usage example for Luminous </h1>
<p> Inspect the source code to see what's going on. </p>

<p>
<?php if (!$use_cache)
  echo "Caching is <strong>disabled</strong>, click <a href='example.php'>here</a> to enable it";
  else
    echo "Caching is <strong>enabled</strong>. If you are seeing errors, you will need to make the directory: "
. realpath("./../") . "/cache/, and make it writable to your server if you intend to use the caching system. Click <a href='example.php?nocache'>here</a> to view this page with caching disabled";
?>
</p>

<p style='margin-top:3em'> 
An unconstrained, uncontained code display. If you want to use it like this, 
set style='padding:0px; margin:0px;' on the body element to remove the white 
border to the left.
</p>
<?php echo luminous('cpp', '#include <stdio.h>
int main()
{
  printf("hello, world");
  return 0;
}
', $use_cache); ?>
  
  
<p>

But you'll find if you only want to display a short code excerpt, it looks a lot better like this, wrapped in a div with 
style= 'margin-left:auto; margin-right:auto; border:1px solid black;'. The margins make it centred. 

</p>

<div style='width:50%; margin-left:auto;margin-right:auto; border:1px solid black;'>
<?php
echo luminous('cpp', '#include <stdio.h>
int main()
{
  printf("hello, world");
  return 0;
}
', $use_cache);
  ?>
</div>


<p>
This is from jQuery, Copyright 2010, John Resig, which I use to show a dimension constrained container with scrollbars.
The style for the container div is: style='width:50%; height:250px; margin-left:auto;margin-right:auto; border:1px solid black; overflow:auto'
</p>
<div style='width:50%; height:250px; margin-left:auto;margin-right:auto; border:1px solid black; overflow:auto'>
<?php

echo luminous('js', 'function cloneCopyEvent(orig, ret) {
  var i = 0;
  
  ret.each(function() {
    if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
      return;
    }
      
    var oldData = jQuery.data( orig[i++] ), curData = jQuery.data( this, oldData), events = oldData && oldData.events;
      
    if ( events ) {
      delete curData.handle;
      curData.events = {};
        
      for ( var type in events ) {
        for ( var handler in events[ type ] ) {
          jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][
          handler ].data );
        }
      }
    }
  });
}', $use_cache);
  ?>
</div>
</body>
</html>
